package com.is416;

public class DataConnection {
	
	public static void main(String [] args) {

        java.sql.Connection conn = null;
        String dbURL = "jdbc:mysql://localhost:3306/foodlover";
        String userName = "root";
        String pwd = "root";

        System.out.println("SQL Test");

        try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                conn = java.sql.DriverManager.getConnection(dbURL,userName,pwd);         		
                       
        }
        catch (Exception e) {
                System.out.println(e);
                System.exit(0);
                }

        System.out.println("Connection established");
        try {
            java.sql.Statement s = conn.createStatement();
            java.sql.ResultSet r = s.executeQuery
            ("SELECT * FROM user");
            while(r.next()) {
                    System.out.println (
                            r.getString("userName") );
                    }
    }
    catch (Exception e) {
            System.out.println(e);
            System.exit(0);
            }
        }


}
